<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>测试</title>
    <script src="../static/js/jQuery3.7.1.js"></script>
    <script src="../static/js/LodopFuncs.js"></script>
    <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
        <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0 pluginspage="install_lodop32.exe"></embed>
    </object>
</head>

<body>
<div class="title">
    <input type="button" value="打印" class="submitBtn" id="pt"/>
</div>
</body>
<script>
    //声明为全局变量
    var LODOP=getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
    console.log("初始化打印机："+checkOrTryHttp());
    $(function () {

        $("#pt").click(function (){

            $.ajax({
                url:"/demo/replace/randomPrint",
                type:"GET",
                data:{
                },
                success:function(data){
                    if(data.errCode!==0) {
                        alert("错误："+data.errMsg);
                    } else {
                        LODOP.PRINT_INIT("打条形码");//首先一个初始化语句
                        // LODOP.ADD_PRINT_BARCODE(28,34,307,47,"128A","data.data.codeNew");
                        let w=200,h=80,left=20,top=30,type='Code93';
                        // data.data.length
                        for (let i = 0; i < data.data.length; i++) {
                            console.log("for:",data.data)
                            let j = i/2;
                            let o = (i-1)/2;
                            if(i%2===0) {
                                console.log("奇数：",(h+top)*i,left,w,h)
                                LODOP.ADD_PRINT_BARCODE(top+(h+top)*j,left,w,h,"128A",data.data[i].codeOld);
                            } else {
                                console.log("偶数：",(h+top)*(i-1),left*2,w,h)
                                LODOP.ADD_PRINT_BARCODE(top+(h+top)*o,left*2+w,w,h,"128A",data.data[i].codeOld);
                            }

                        }
                        LODOP.PREVIEW();
                        LODOP.PRINT();
                    }
                }
            });
        });


    });
</script>
<style>
    span{
        float: left;
        text-align: right;
    }
    .title{
        margin: 0 auto;
    }
    .input_text {
        width: 140px;
        height: 22px;
        line-height: 22px;
        border: 1px solid #a5c3e0;
        border-top: 1px solid #89accd;
        border-right: 1px solid #89accd;
        padding: 0 3px;
        border-radius: 3px;
        box-shadow: 1px 2px 2px #e5eaee inset;
        font-size: 12px;
        /*margin-left: 90px;*/
    }
    .submitBtn{
        margin-top: 10px;
        margin-left: 30px;
        background-color: #2283C5 !important;
        border: 4px solid #2283C5;
        color: #FFFFFF !important;
        border-radius: 3px;
        text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25) !important;
        transition: all 0.15s ease 0s;
        vertical-align: middle;
    }
    .submitBtn:hover{
        background-color: #045E9F !important;
        border: 4px solid #045E9F;
    }
    .submitBtn:active{
        left:1px;
        top:1px;
    }
</style>
</html>